﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Daco
{
    public class CTree : ITree
    {
        #region ITree Members
        private TreeNodeCollection _nodes = new TreeNodeCollection();
        public TreeNodeCollection Nodes
        {
            get { return _nodes; }
        }

        private CTreeNode _selectedNode = null;
        public ITreeNode SelectedNode
        {
            get
            {
                return _selectedNode;
            }
            //set
            //{
            //    if (value != _selectedNode)
            //    {
            //        _selectedNode = value;
            //    }
            //}
        }

        #endregion

        public CTree()
        {

        }
    }

    public class CTreeNode : ITreeNode
    {
        #region ITreeNode Members
        private string _name = string.Empty;
        public string Name
        {
            get { return _name; }
            set
            {
                if (string.IsNullOrEmpty(_name) || string.Compare(value, _name, StringComparison.CurrentCultureIgnoreCase) == 0)
                    _name = value;
            }
        }
        private string _value = string.Empty;
        public string Value
        {
            get { return _value; }
            set
            {
                if (string.IsNullOrEmpty(_value) || string.Compare(value, _value, StringComparison.CurrentCultureIgnoreCase) == 0)
                    _value = value;
            }
        }
        public bool HasNodes
        {
            get { return Nodes.Count > 0; }
        }
        private bool _isSelected = false;
        public bool Selected
        {
            get { return _isSelected; }
            set { _isSelected = value; }
        }
        private CTreeNode _parent = null;
        public ITreeNode Parent
        {
            get
            {
                return _parent;
            }
        }

        private TreeNodeCollection _nodes = new TreeNodeCollection();
        public TreeNodeCollection Nodes
        {
            get { return _nodes; }
        }

        #endregion

        public CTreeNode()
        {
        }

        public CTreeNode(string name)
        {
            this.Name = name;
        }

        public CTreeNode(string name, string value)
        {
            this.Name = name;
            this.Value = value;
        }

        public CTreeNode(string name, string value, bool isSelected)
            : this(name, value)
        {
            _isSelected = isSelected;
        }
    }
}
